<template>
    <div>
        <p>姓名: <input type="text" v-model="name" placeholder="输入姓名"></p>
        <p>车牌号: <input type="text" v-model="title" placeholder="输入车牌号"></p>
        <p>选择小区: <select v-model="park_id">
            <option v-for="park in parkList" :value="park.id">{{park.title}}</option>
        </select></p>
        <p><button @click="login">进入小区</button></p>
    </div>
</template>

<script>
    export default {
        name: "login_park",
        data() {
            return {
                name: '',
                title: '',
                parkList: [],
                park_id: '',
            }
        },
        created() {
            this.$axios({
                url: 'park/park'
            }).then(resp=>{
                this.parkList = resp.data
            })
        },
        methods: {
            login(){
                if (!this.title){
                    this.$router.push(`/park_park?park_id=${this.park_id}`)
                    return
                }
                this.$axios({
                    url: 'park/park/',
                    method: 'POST',
                    data: {
                        name: this.name,
                        title: this.title,
                        park_id: this.park_id
                    }
                }).then(resp=>{
                    alert(resp.data.msg);
                    if (resp.data.code==200){
                        this.$router.push(`/park_park?park_id=${this.park_id}`)
                    }
                })
            }
        },
        computed: {},
        filters: {},
        watch: {},
    }
</script>

<style scoped>

</style>
